package org.yn.auth.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yn.auth.domain.Role;
import org.yn.auth.dto.RoleDTO;
import org.yn.auth.mapper.RoleMapper;
import org.yn.auth.service.IRoleService;
import org.yn.base.service.impl.BaseServiceImpl;
import org.yn.base.util.PageInfo;
import org.yn.query.RoleQuery;

import java.util.List;
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService  {

    @Autowired
    RoleMapper roleMapper;
//
//    @Override
//    public void update(Role role) {
//        roleMapper.update(role);
//    }
//
//    @Override
//    public void insert(Role role) {
//        roleMapper.insert(role);
//    }
//
//    @Override
//    public List<Role> selectAll() {
//        return roleMapper.selectAll();
//    }
//
//    @Override
//    public Role selectById(Long id) {
//        return roleMapper.selectById(id);
//    }
//
//    @Override
//    public void delete(Long id) {
//        roleMapper.delete(id);
//    }
//
//    @Override
//    public void batchDelete(List<Long> ids) {
//        roleMapper.batchDelete(ids);
//    }


    @Override
    public PageInfo<Role> queryPage(RoleQuery roleQuery) {
        Integer total =roleMapper.countTotal(roleQuery);
        if (total==0){
            return new PageInfo<Role>();//返回一个空的
        }
        //查询分页数据
        List<Role> list= roleMapper.queryPage(roleQuery);

        return new PageInfo<Role>(total, list);
    }



    @Override
    public void insertByRoleId(RoleDTO roleDTO) {
        //删除该角色的权限
        roleMapper.deleteByRoleId(roleDTO.getId());
        //保存新的
        roleMapper.insertByRoleId(roleDTO);
    }

    @Override
    public List<String> selectByRoleId(Long id) {
        return roleMapper.selectByRoleId(id);
    }
}
